<?php
/**
 * Created by PhpStorm.
 *
 * @author Tian.Yuxing
 * @email tianyuxing@sciall.org.cn
 * Date: 2025/11/14
 * Time: 14:02
 */

namespace Modules\Common\Repository\Options;

use Modules\User\Models\User;

/**
 * Modules\Common\Repository\Options AdminUser.
 */
class Admin implements OptionInterface
{
    public function get(): array
    {
        // 构建查询条件，排除角色和职位关联数据，只查询ID和用户名字段
        $query = User::query()->without(['roles', 'jobs'])->select(['id', 'username']);
        // 获取查询结果
        $users = $query->limit(10)->get();
        // 如果没有找到用户，返回空数组
        if ($users->isEmpty()) {
            return [];
        }
        // 遍历用户数据，构建选项数组
        $options = [];
        foreach ($users as $item) {
            $options[] = [
                'label' => $item->username,
                'value' => $item->id,
            ];
        }
        return $options;
    }
}